home *** CD-ROM | disk | FTP | other *** search
/ Champak 52 / Volume 52 - JOGO DISK .iso / Games / skipandgouls.swf / scripts / __Packages / characters / DutchManManager.as < prev    next >
Text File  |  2007-10-01  |  2KB  |  70 lines

  1. class characters.DutchManManager extends sarbakan.visual.element.DynamicElement
  2. {
  3.    static var PICK_DELAY = 50;
  4.    function DutchManManager()
  5.    {
  6.       super();
  7.       this.bAlwaysActive = true;
  8.       this.aDutchMan = [];
  9.       this.enable();
  10.       this.nPickDelayCount = 0;
  11.    }
  12.    function add(l_oDutchMan, l_nX, l_nY)
  13.    {
  14.       this.aDutchMan.push({dutchman:l_oDutchMan,x:l_nX,y:l_nY});
  15.    }
  16.    function remove(l_oDutchMan)
  17.    {
  18.       for(var _loc3_ in this.aDutchMan)
  19.       {
  20.          if(this.aDutchMan[_loc3_].dutchman == l_oDutchMan)
  21.          {
  22.             this.aDutchMan.splice(_loc3_,1);
  23.             break;
  24.          }
  25.       }
  26.       if(l_oDutchMan == this.oCurrentDutchman)
  27.       {
  28.          this.onDutchManOut();
  29.       }
  30.    }
  31.    function onDutchManOut()
  32.    {
  33.       this.oCurrentDutchman.setState("idle");
  34.       this.setState("idle");
  35.    }
  36.    function idle()
  37.    {
  38.       if(++this.nPickDelayCount == characters.DutchManManager.PICK_DELAY)
  39.       {
  40.          this.nPickDelayCount = 0;
  41.          this.setState("pick");
  42.       }
  43.    }
  44.    function pick()
  45.    {
  46.       var _loc4_ = undefined;
  47.       var _loc3_ = 100000;
  48.       var _loc2_ = undefined;
  49.       for(var _loc5_ in this.aDutchMan)
  50.       {
  51.          _loc2_ = sarbakan.utils.MoreMath.getDistance(this.aDutchMan[_loc5_].dutchman.mc._x,this.aDutchMan[_loc5_].dutchman.mc._y,this.oOwner.oDynamicElements.spongebob.mc._x,this.oOwner.oDynamicElements.spongebob.mc._y);
  52.          if(_loc2_ < _loc3_)
  53.          {
  54.             _loc4_ = _loc5_;
  55.             _loc3_ = _loc2_;
  56.          }
  57.       }
  58.       this.oCurrentDutchman = this.aDutchMan[_loc4_].dutchman;
  59.       if(this.oCurrentDutchman)
  60.       {
  61.          this.aDutchMan[_loc4_].dutchman.setState("idleIn");
  62.          this.setState("wait");
  63.       }
  64.       else
  65.       {
  66.          this.setState("idle");
  67.       }
  68.    }
  69. }
  70.